<?php
class view_theme{
	
	/**
	 * wczytaj liste sekcji dla strony
	 *
	 * @param Int $__page
	 * @param Int $__section
	 * @return Str
	 */
	private static function _fetch_section($__page,$__section, $__from_db=null){
		global $smarty, $objSession, $parameters, $user, $config;
		if ( !$__page ) $__from_db = null;
		if (!is_null($__from_db)){
			$__section_body = config::_fetch_section_form_db("{$__page},{$__section},{$config->__lang}");
			if ($objSession->IsLoggedIn() && $user->stanowisko == "a") 
			$__section_body = (!theme::_get_page_atribut("typ_page",$config->__lang,$__page))	? "<!--panel--><div style=\" margin: 0px auto; border: dotted 1px #ff0000; \">
				<div class=\"section-toolbar\" style=\"padding: 0px; margin: 0px; margin-bottom: 0px; border-bottom: dotted 1px #ff0000;  background: #fff; \"><a  href =\"sekcja,{$__page},{$__section},{$objSession->userLanguage}.html\"><img src=\"".HTTP_URL."public/skins/icons/16_layout_edit.png\" border=0 alt=\"edytuj treść sekcji {$__section}\" title=\"edytuj treść sekcji {$__section}\"/></a></div><!--/panel-->".$__section_body."<!--panel--></div><!--/panel-->" : $__section_body;
			return $__section_body;
		}
	}
	
	/**
	 * dpdaje do zmiennych smarty tresc sekcji
	 *
	 * @param unknown_type $__section_info
	 * @param unknown_type $__theme_info
	 * @param unknown_type $__page
	 */
	public static function __show_section_text($__section_info,$__theme_info=1,$__page){
		global $smarty,$user;
		if (!empty($__section_info)){
			foreach ($__section_info as $__section) {
				$__section_body = view_theme::_fetch_section($__page,$__section['id_section'],'get_from_db');
				$smarty->assign("section{$__section['id_section']}",$__section_body);
			}			
		}else{
			tools::_assign("section1","strona w budowie...");
		}
	}
	
	public static function __display_page($__theme_info){
		global $smarty,$config;
		if (isset($config->cmsSettings['szablon']) && isset($config->cmsSettings['ramka_theme']) && isset($config->cmsSettings['ramka_theme_kolor'])){
//			$tmp__ = str_split($config->cmsSettings['szablon'],2);
//			$theme_group = $tmp__[0];
			$szablon = $config->cmsSettings['szablon'];
			$ramka_theme = $config->cmsSettings['ramka_theme'];
			$ramka_theme_kolor = $config->cmsSettings['ramka_theme_kolor'];
		}else{
//			$theme_group = '00';
		}
		if ($__theme_info != '_') $__tpl = "theme_{$szablon}/{$ramka_theme}_{$ramka_theme_kolor}/theme_{$__theme_info}.tpl";
		else $__tpl = "theme_{$__theme_info}.tpl";
		if ($smarty->template_exists($__tpl)){
			$smarty->display($__tpl);
		}else{
			echo "brak pliku theme : {$__tpl}";
		}
	}
	
	public static function showRamki(){
		global $settings,$config;
		if ( $config->__isset('szablon')) $settings['szablon'] = $config->szablon;
		else if(is_array($settings)) $settings['szablon'] = ((isset($settings['szablon']) && !empty($settings['szablon']))? $settings['szablon'] : "0000");
		$szablony = unserialize(SZABL);
		$ramki = unserialize(RAMKI);
		tools::_assign("szablony",$szablony);
		tools::_assign("settings",$settings);
		tools::_assign("ramki",$ramki[$settings['szablon']]);

		$domena = str_replace('www.','',$_SERVER['HTTP_HOST']);
		if( config::sprawdzTypDomeny($domena))  tools::_assign("typ_domeny","main");	
		tools::_display("section/admin/pages/const_theme_edit.tpl");
	}
}
?>